define(["jquery","layuiall","zTree","jqform","jq_request","helper"],function ($,layui,zTree,jqform,jq_request,helper) {
    var form = layui.form;
    controller = {
        index:function () {
            form.on('switch(status)', function(data){
                var status = 0;
                if(data.elem.checked){
                    status = 1
                }
                $.ajax({
                    type:'post',
                    data:{
                        id:data.value,
                        status:status
                    },
                    url:$(data.elem).attr("data-url"),
                    success:function (res) {
                        layer.msg(res.msg)
                    }
                })
            });
            form.on('switch(is_admin)', function(data){
                var status = 0;
                if(data.elem.checked){
                    status = 1
                }
                $.ajax({
                    type:'post',
                    data:{
                        id:data.value,
                        is_admin:status
                    },
                    url:$(data.elem).attr("data-url"),
                    success:function (res) {
                        layer.msg(res.msg)
                    }
                })
            });
            $(".reset-pwd").click(function () {
                url = $(this).attr("data-url");
                id = $(this).attr("data-id")
                layer.prompt(function(value, index, elem){
                    $.ajax({
                        type:'post',
                        url:url,
                        data:{
                            id:id,
                            password:value
                        },
                        success:function (res) {
                            layer.msg(res.msg);
                            layer.close(index);
                        }
                    })
                });
            })
            jqform.delete()
            form.on('checkbox(select-all)', function(data){

                if(data.elem.checked==true){
                    $("input[name='idList[]']").prop('checked',true)
                }else {
                    $("input[name='idList[]']").prop('checked',false)
                }
                form.render('checkbox');
            });
            $(".score").click(function () {
                var _this = $(this);
                layer.prompt(function(value, index, elem){
                    $.ajax({
                        type:'post',
                        url:_this.data("href"),
                        dataType:'json',
                        data:{
                            price:value,
                            //user_id:_this.data("user_id")
                        },
                        success:function (res) {
                            layer.msg(res.msg,{
                                end:function () {
                                    layer.closeAll()
                                }
                            })
                        },
                        error:function (err) {
                            layer.msg("网络错误请稍后再试")
                        }
                    })
                });
            })
        },
        adduser:function () {
            $("#test1").click(function () {
                uploadFiles({
                    url: '/admin/webupload/webuploader/multi/1/filetype/image/app/admin/tab/local',
                    file:function (res) {
                        var file = JSON.parse(res);
                        $("#app-photo").find("input[name='avatar']").val(file[0].filepath);
                        $("#app-photo").find("img").attr("src",file[0].preview_url);
                        localStorage.removeItem("upload");
                    }
                });
            });
           /* uploadFile({
                elm:'#test1',
                url:"/admin/webupload/upuseravatar",
                table:'#app-photo',
                multiple:false,
                exts:'jpg|png|bmp|jpeg|avg',
                inputName:'avatar'
            });*/
            jqform.init()
        },
        edituser:function () {
            $("#test1").click(function () {
                uploadFiles({
                    url: '/admin/webupload/webuploader/multi/1/filetype/image/app/admin/tab/local',
                    file:function (res) {
                        var file = JSON.parse(res);
                        $("#app-photo").find("input[name='avatar']").val(file[0].filepath);
                        $("#app-photo").find("img").attr("src",file[0].preview_url);
                        localStorage.removeItem("upload");
                    }
                });
            });
            /*uploadFile({
                elm:'#test1',
                url:"/admin/webupload/upuseravatar",
                table:'#app-photo',
                multiple:false,
                exts:'jpg|png|bmp|jpeg|avg',
                inputName:'avatar'
            });*/
            jqform.init()
        }
    }
    return controller;
})